package leetcode;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-22 11:29
 **/
public class LeetCode232 {
    Deque<Integer> stackin;
    Deque<Integer> stackout;
    int front;

    public LeetCode232() {
        stackin = new LinkedList<>();
        stackout = new LinkedList<>();
    }

    /*public void push(int x) {
        stackin.push(x);
    }

    public int pop() {
        if (!stackout.isEmpty()) {
            return stackout.pop();
        }
        if (!stackin.isEmpty()) {
            while (!stackin.isEmpty()) {
                stackout.push(stackin.pop());
            }
            return stackout.pop();
        }
        return -1;
    }

    public int peek() {
        if (!stackout.isEmpty()) {
            return stackout.peek();
        }
        if (!stackin.isEmpty()) {
            while (!stackin.isEmpty()) {
                stackout.push(stackin.pop());
            }
            return stackout.peek();
        }
        return -1;
    }

    public boolean empty() {
        return stackin.isEmpty() && stackout.isEmpty();
    }*/

    public void push(int x) {
        if (stackin.isEmpty()) {
            front = x;
        }
        stackin.push(x);
    }

    public int pop() {
        if (stackout.isEmpty()) {
            while (!stackin.isEmpty()) {
                stackout.push(stackin.pop());
            }
        }
        return stackout.pop();
    }

    public int peek() {
        if (!stackout.isEmpty()) {
            return stackout.peek();
        }
        return front;
    }

    public boolean empty() {
        return stackin.isEmpty() && stackout.isEmpty();
    }


}
